<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('oms_order')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <oms-order-modal ref="modalForm" @ok="modalFormOk"></oms-order-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import OmsOrderModal from './modules/OmsOrderModal'

  export default {
    name: 'OmsOrderList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      OmsOrderModal
    },
    data () {
      return {
        description: 'oms_order管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'member_id',
            align:"center",
            dataIndex: 'memberId'
          },
          {
            title:'订单号',
            align:"center",
            dataIndex: 'orderSn'
          },
          {
            title:'使用的优惠券',
            align:"center",
            dataIndex: 'couponId'
          },
          {
            title:'用户名',
            align:"center",
            dataIndex: 'memberUsername'
          },
          {
            title:'订单总额',
            align:"center",
            dataIndex: 'totalAmount'
          },
          {
            title:'应付总额',
            align:"center",
            dataIndex: 'payAmount'
          },
          {
            title:'运费金额',
            align:"center",
            dataIndex: 'freightAmount'
          },
          {
            title:'促销优化金额（促销价、满减、阶梯价）',
            align:"center",
            dataIndex: 'promotionAmount'
          },
          {
            title:'积分抵扣金额',
            align:"center",
            dataIndex: 'integrationAmount'
          },
          {
            title:'优惠券抵扣金额',
            align:"center",
            dataIndex: 'couponAmount'
          },
          {
            title:'后台调整订单使用的折扣金额',
            align:"center",
            dataIndex: 'discountAmount'
          },
          {
            title:'支付方式【1->支付宝；2->微信；3->银联； 4->货到付款；】',
            align:"center",
            dataIndex: 'payType'
          },
          {
            title:'订单来源[0->PC订单；1->app订单]',
            align:"center",
            dataIndex: 'sourceType'
          },
          {
            title:'订单状态【0->待付款；1->待发货；2->已发货；3->已完成；4->已关闭；5->无效订单】',
            align:"center",
            dataIndex: 'status'
          },
          {
            title:'物流公司(配送方式)',
            align:"center",
            dataIndex: 'deliveryCompany'
          },
          {
            title:'物流单号',
            align:"center",
            dataIndex: 'deliverySn'
          },
          {
            title:'自动确认时间（天）',
            align:"center",
            dataIndex: 'autoConfirmDay'
          },
          {
            title:'可以获得的积分',
            align:"center",
            dataIndex: 'integration'
          },
          {
            title:'可以获得的成长值',
            align:"center",
            dataIndex: 'growth'
          },
          {
            title:'发票类型[0->不开发票；1->电子发票；2->纸质发票]',
            align:"center",
            dataIndex: 'billType'
          },
          {
            title:'发票抬头',
            align:"center",
            dataIndex: 'billHeader'
          },
          {
            title:'发票内容',
            align:"center",
            dataIndex: 'billContent'
          },
          {
            title:'收票人电话',
            align:"center",
            dataIndex: 'billReceiverPhone'
          },
          {
            title:'收票人邮箱',
            align:"center",
            dataIndex: 'billReceiverEmail'
          },
          {
            title:'收货人姓名',
            align:"center",
            dataIndex: 'receiverName'
          },
          {
            title:'收货人电话',
            align:"center",
            dataIndex: 'receiverPhone'
          },
          {
            title:'收货人邮编',
            align:"center",
            dataIndex: 'receiverPostCode'
          },
          {
            title:'省份/直辖市',
            align:"center",
            dataIndex: 'receiverProvince'
          },
          {
            title:'城市',
            align:"center",
            dataIndex: 'receiverCity'
          },
          {
            title:'区',
            align:"center",
            dataIndex: 'receiverRegion'
          },
          {
            title:'详细地址',
            align:"center",
            dataIndex: 'receiverDetailAddress'
          },
          {
            title:'订单备注',
            align:"center",
            dataIndex: 'note'
          },
          {
            title:'确认收货状态[0->未确认；1->已确认]',
            align:"center",
            dataIndex: 'confirmStatus'
          },
          {
            title:'删除状态【0->未删除；1->已删除】',
            align:"center",
            dataIndex: 'deleteStatus'
          },
          {
            title:'下单时使用的积分',
            align:"center",
            dataIndex: 'useIntegration'
          },
          {
            title:'支付时间',
            align:"center",
            dataIndex: 'paymentTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'发货时间',
            align:"center",
            dataIndex: 'deliveryTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'确认收货时间',
            align:"center",
            dataIndex: 'receiveTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'评价时间',
            align:"center",
            dataIndex: 'commentTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'修改时间',
            align:"center",
            dataIndex: 'modifyTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/order/omsOrder/list",
          delete: "/order/omsOrder/delete",
          deleteBatch: "/order/omsOrder/deleteBatch",
          exportXlsUrl: "/order/omsOrder/exportXls",
          importExcelUrl: "order/omsOrder/importExcel",
          
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'int',value:'memberId',text:'member_id'})
        fieldList.push({type:'string',value:'orderSn',text:'订单号'})
        fieldList.push({type:'int',value:'couponId',text:'使用的优惠券'})
        fieldList.push({type:'string',value:'memberUsername',text:'用户名'})
        fieldList.push({type:'number',value:'totalAmount',text:'订单总额'})
        fieldList.push({type:'number',value:'payAmount',text:'应付总额'})
        fieldList.push({type:'number',value:'freightAmount',text:'运费金额'})
        fieldList.push({type:'number',value:'promotionAmount',text:'促销优化金额（促销价、满减、阶梯价）'})
        fieldList.push({type:'number',value:'integrationAmount',text:'积分抵扣金额'})
        fieldList.push({type:'number',value:'couponAmount',text:'优惠券抵扣金额'})
        fieldList.push({type:'number',value:'discountAmount',text:'后台调整订单使用的折扣金额'})
        fieldList.push({type:'int',value:'payType',text:'支付方式【1->支付宝；2->微信；3->银联； 4->货到付款；】'})
        fieldList.push({type:'int',value:'sourceType',text:'订单来源[0->PC订单；1->app订单]'})
        fieldList.push({type:'int',value:'status',text:'订单状态【0->待付款；1->待发货；2->已发货；3->已完成；4->已关闭；5->无效订单】'})
        fieldList.push({type:'string',value:'deliveryCompany',text:'物流公司(配送方式)'})
        fieldList.push({type:'string',value:'deliverySn',text:'物流单号'})
        fieldList.push({type:'int',value:'autoConfirmDay',text:'自动确认时间（天）'})
        fieldList.push({type:'int',value:'integration',text:'可以获得的积分'})
        fieldList.push({type:'int',value:'growth',text:'可以获得的成长值'})
        fieldList.push({type:'int',value:'billType',text:'发票类型[0->不开发票；1->电子发票；2->纸质发票]'})
        fieldList.push({type:'string',value:'billHeader',text:'发票抬头'})
        fieldList.push({type:'string',value:'billContent',text:'发票内容'})
        fieldList.push({type:'string',value:'billReceiverPhone',text:'收票人电话'})
        fieldList.push({type:'string',value:'billReceiverEmail',text:'收票人邮箱'})
        fieldList.push({type:'string',value:'receiverName',text:'收货人姓名'})
        fieldList.push({type:'string',value:'receiverPhone',text:'收货人电话'})
        fieldList.push({type:'string',value:'receiverPostCode',text:'收货人邮编'})
        fieldList.push({type:'string',value:'receiverProvince',text:'省份/直辖市'})
        fieldList.push({type:'string',value:'receiverCity',text:'城市'})
        fieldList.push({type:'string',value:'receiverRegion',text:'区'})
        fieldList.push({type:'string',value:'receiverDetailAddress',text:'详细地址'})
        fieldList.push({type:'string',value:'note',text:'订单备注'})
        fieldList.push({type:'int',value:'confirmStatus',text:'确认收货状态[0->未确认；1->已确认]'})
        fieldList.push({type:'int',value:'deleteStatus',text:'删除状态【0->未删除；1->已删除】'})
        fieldList.push({type:'int',value:'useIntegration',text:'下单时使用的积分'})
        fieldList.push({type:'date',value:'paymentTime',text:'支付时间'})
        fieldList.push({type:'date',value:'deliveryTime',text:'发货时间'})
        fieldList.push({type:'date',value:'receiveTime',text:'确认收货时间'})
        fieldList.push({type:'date',value:'commentTime',text:'评价时间'})
        fieldList.push({type:'date',value:'modifyTime',text:'修改时间'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>